<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>配置</title>
    <link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css"/>
</head>
<body>
<div class="layui-form-item" name="last[]" id="main" tag="0">
<!--        <div class="layui-input-block" style="margin-left: 480px">-->
<!--            <button id="login" type="button" class="layui-btn layui-btn-normal layui-btn-sm">-->
<!--                <i class="layui-icon">登录账号</i>-->
<!--            </button>-->
<!--            <button id="add" type="button" class="layui-btn layui-btn-warm layui-btn-sm">-->
<!--                <i class="layui-icon">添加账号</i>-->
<!--            </button>-->
<!--        </div>-->

        <div class="layui-form-item">
            <label class="layui-form-label">监控号</label>
            <div class="layui-input-inline">
                <input type="text" name="mainNumber[]" id="monitor_0" required lay-verify="required" placeholder="请输入账号"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">目标号</label>
            <div class="layui-input-inline">
                <input type="text" name="targetOrder[]" id="targetOrder_0" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">兑换金额</label>
                <div class="layui-input-inline">
                    <input type="text" name="exchange[]" id="exchange_0" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">下单金额</label>
                <div class="layui-input-inline">
                    <input type="text" name="money[]" id="money_0" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">下单时间间隔（秒）</label>
                <div class="layui-input-inline">
                    <input type="text" name="interval[]" id="interval_0" placeholder="请输入" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <button id="login" type="button" onclick="login(0)"
                        class="layui-btn layui-btn-normal layui-btn-sm">
                    <i class="layui-icon">登录</i>
                </button>
                <label class="layui-form-label"></label>
                <button name="subOrder[]" type="button" onclick="subOrder(0)"
                        class="layui-btn layui-btn-normal layui-btn-sm">
                    <i class="layui-icon">开始下单</i>
                </button>
                <button name="stopOrder[]" type="button" onclick="stopOrder(0)"
                        class="layui-btn layui-btn-normal layui-btn-sm">
                    <i class="layui-icon">停止下单</i>
                </button>
            </div>
        </div>
</div>


</body>
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.5.1.min.js"></script>
<script src="/static/layui/layui.js" ></script>
<script type="text/javascript" >
    $(function () {
    });

    function login(num) {

        $.ajax({
            url:"./login",
            contentType:"application/json;charset=UTF-8",
            type:"post",
            data:JSON.stringify({"slaveList":[{"monitor":$("#monitor_"+num).val(),
                    "exchange":$("#exchange_"+num).val(),
                    "money":$("#money_"+num).val(),
                    "targetOrder":$("#targetOrder_"+num).val(),
                    "interval":$("#interval_"+num).val()}]}),
            dataType:"json",
            success:function(data){
                if(data){
                    alert("登录成功")

                }else{
                    alert("登录失败")

                }
            }
        })
    }
    //监控号下单
    function subOrder(num) {
        $.ajax({
            "url": "./bet",
            "data": {
                "sid": $("#monitor_" + num).val(),
                "second": $("#interval_" + num).val(),
                "is_bet":true
            },
            "dataType": "json",
            success: function (data) {
                if(data){
                    alert("开始下单")
                }else{
                    alert("下单失败")
                }
            }
        })
    }

    //停止下单
    function stopOrder(num) {
        $.ajax({
            "url": "./bet",
            "data": {
                "sid": $("#monitor_" + num).val(),
                "second": $("#interval_" + num).val(),
                "is_bet":false
            },
            "dataType": "json",
            success: function (data) {
                if(data){
                    alert("停止下单");
                }else{
                    alert("停止下单异常")
                }

            }
        })
    }
</script>


</html>